// pages/hotel/hotel.js
import http from "../../utils/http"
Page({
    data: {
        height: 70,//初始高
        chushi: 250,
        isShow: true,//控制小笔的显示和隐藏
        value: "",//输入框的value
        shopInfo: [],//所有信息
        defaultHeight: "130rpx",
        contant: "235rpx",
        tag:"true"

    },
    onLoad: function (options) {
        this.shopInfo()
    },
    onShow: function () {
        this.shopInfo()
    },
    async shopInfo() {
        let option = {
            url: "/mainPageInfo",
            data: {
                storeId: '33',
                xpoint: '117.289604',
                ypoint: '34.80101',
                xcFlag: '0'
            }
        }
        let res = await http(option)
        console.log(res);
        if(res.data.status == 200){
            for(var i = 0;i < res.data.data.commentList.length;i++){
                res.data.data.commentList[i].addTime  = [new Date(res.data.data.commentList[i].addTime).getFullYear(),new Date(res.data.data.commentList[i].addTime).getMonth()+1,new Date(res.data.data.commentList[i].addTime).getDate()] ;
            }
            res.data.data.store.openTime = res.data.data.store.openTime.split("-")
            this.setData({
                shopInfo: res.data.data
            })
        }else{
            wx.showToast({
              title: '请求超时,请稍后再试',
            })
        }
        },

    // 点击查看更多
    more() {
        if(this.data.tag == "true"){
            let defaultHeight = "260rpx"
            let contant = "365rpx"
            let tag = "false"
            this.setData({
                defaultHeight,
                contant,
                tag
            })
        }else{
            let tag = "true"
          this.setData({
            defaultHeight:"130rpx",
            contant:"235rpx",
            tag
          })
        }

    },
    // 地图导航
    clickMap() {
        // if (!this.data.shopInfo.xpoint || this.data.shopInfo.ypoint) {
        //     wx.showToast({
        //         title: '商家未设置位置信息',
        //     })
        //     return
        // }
        // let lon = parseFloat(this.shopInfo.xpoint)
        // let lat = parseFloat(this.shopInfo.ypoint)
        wx.openLocation({
            latitude: 117.289604,
            longitude: 34.80101,
            scale: 18,
            fail: () => {
                wx.showToast({
                    title: '无地址信息',
                    icon: "none"
                })
            }
        })
    },
    // 拨打电话
    call() {
        wx.makePhoneCall({
            phoneNumber: "13371420823",
            success(res) {
                console.log(res)
            }
        })
    },
    // 触发焦点
    focus() {
        this.setData({
            isShow: false,
            height: 150
        })
    },
    // 失焦
    blur() {
        if (this.value != "") {
            console.log(1);
            this.setData({
                isShow: false,
                chushi: 0,
                height: 70
            })
        } else {
            this.setData({
                isShow: true
            })
        }
    },
    // 评论
    add(e) {
        let value = e.detail.value
        if (value) {
            this.setData({
                value
            })
        }
    },
    send(e) {
        console.log(e);
        wx.showToast({
            title: e.detail.value,
        })
    },

})